<style lang="scss">
</style>
<template>
  <span>
    <a style="font-size:14px" @click="applySubmit()"  >{{ text }}</a>
  </span>
</template>

<script>
import { definitionStartByDataId } from "@views/flowable/api/definition";

export default {
  name: "ActApplyBtn",
  components: {},
  props: {
    btnType: { type: String, default: "link", required: false },
    /**/
    assign: {
      type: Blob,
      default: false,
    },
    dataId: {
      type: String,
      default: "",
      required: true,
    },
    serviceName: {
      type: String,
      default: "",
      required: true,
    },
    variables: {
      type: Object,
      default: {},
    },
    text: {
      type: String,
      default: "提交审核",
      required: false,
    },
  },
  data() {
    return {
      modalVisible: false,
      submitLoading: false,
      form: {},
    };
  },
  created() {},
  watch: {},
  methods: {
    applySubmit() {
      if (this.dataId && this.dataId.length < 1) {
        this.error = "必须传入参数dataId";
        this.$message.error(this.error);
        return;
      }
      if (this.serviceName && this.serviceName.length < 1) {
        this.error = "必须传入参数serviceName";
        this.$message.error(this.error);
        return;
      } else {
        this.error = "";
      }
      this.submitLoading = true;
      var params = Object.assign(
        {
          dataId: this.dataId,
          assignee: "",
        },
        this.variables
      );

      definitionStartByDataId(this.dataId, this.serviceName, params)
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message);
            this.$emit("success");
          } else {
            this.$message.error(res.message);
          }
        })
        .finally(() => (this.submitLoading = false));
    },
  },
};
</script>
